package com.taijihuabao.common.activititasklistener.expensetasklistener;

import com.taijihuabao.common.redisconfig.UserLoad;
import com.taijihuabao.modules.entity.UserEntity;
import com.taijihuabao.modules.mapper.UserMapper;
import com.taijihuabao.modules.model.user.vo.UserInfoVO;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @title: approvalListener
 * @Author luoxianan
 * @Date: 2021/12/9 14:25
 * @Version 1.0
 */
@Component
public class ApprovalListener implements TaskListener {
    @Autowired
    private UserMapper userMapper;
    private final String TEXT = "员工申请报销";
    private final String TYPE= "create";
    @Override
    public void notify(DelegateTask delegateTask) {
            if (delegateTask.getName().equals(TEXT)&& TYPE.equals(delegateTask.getEventName())){
                UserEntity user = UserLoad.getUser();
                Long id = user.getId();
                //指定任务负责人
                UserInfoVO userInfoVO = userMapper.selectById(id);
                //mapper传入审批人
                delegateTask.setAssignee(String.valueOf(userInfoVO.getId()));
            }

    }
}
